package com.accp.vehiclecare.action.zbaction;

import com.accp.vehiclecare.biz.zbbiz.StaffBiz;
import com.accp.vehiclecare.pojo.*;
import com.accp.vehiclecare.vo.zbvo.StaffVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags="日志接口模块")
@RestController
@RequestMapping("/api/staff")
public class StaffAction {
    @Autowired
    private StaffBiz sbiz;

    @ApiOperation(value="分页查询", notes = "根据当前页数，每页多少行查询出分页数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path", name = "p", value = "当前页数", example = "1", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="path", name = "s", value = "每页多少行", example = "3", required = true, dataType = "int")
    })
    @GetMapping("{p}/{s}")
    public PageInfo<StaffVo> queryAllStaff(@PathVariable Integer p, @PathVariable Integer s) {
        return sbiz.queryAll(p,s);
    }
    @ApiOperation(value="删除", notes = "根据员工id进行删除", httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path", name = "id", value = "员工id", example = "1", required = true, dataType = "int")
    })
    @DeleteMapping("remove/{id}")
    public Map<String,Object> removeStaff(@PathVariable Integer id){
        Map<String,Object> message=new HashMap<String,Object>();
        boolean count=sbiz.deleteStaff(id);
        if (count){
            message.put("code","200");
            message.put("msg","ok");
        }
        return message;
    }
    @ApiOperation(value="新增日志", notes = "根据前端发送的对象进行新增", httpMethod = "POST")
    @PostMapping("add")
    public Map<String,Object> addStaff(@RequestBody Employee emp){
        Map<String,Object> message=new HashMap<String,Object>();
        emp.setEtypeid(1);
        emp.setDimissionid(0);
        boolean count= sbiz.addStaff(emp);
        if (count){
            message.put("code","200");
            message.put("msg","ok");
        }
        return message;
    }
    @ApiOperation(value="门店查询", notes = "查询全部门店", httpMethod = "GET")
    @GetMapping("shop")
    public List<Shop> queryShop() {
        return sbiz.queryShop();
    }
    @ApiOperation(value="部门查询", notes = "根据门店id查询部门", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path", name = "sid", value = "门店id", example = "1", required = true, dataType = "int")
    })
    @GetMapping("dep/{sid}")
    public List<Department> queryDep(@PathVariable Integer sid) {
        return sbiz.queryDep(sid);
    }
    @ApiOperation(value="部门组查询", notes = "根据部门id查询部门", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path", name = "did", value = "部门id", example = "1", required = true, dataType = "int")
    })
    @GetMapping("group/{did}")
    public List<Group> queryGroup(@PathVariable Integer did) {
        return sbiz.queryGrou(did);
    }
    @ApiOperation(value="岗位查询", notes = "查询全部岗位", httpMethod = "GET")
    @GetMapping("station")
    public List<Station> queryStat() {
        return sbiz.queryStat();
    }
    @ApiOperation(value="角色查询", notes = "查询全部角色", httpMethod = "GET")
    @GetMapping("jur")
    public List<Jurisdiction> queryJur() {
        return sbiz.queryJur();
    }
    @ApiOperation(value="角色指定查询", notes = "查询指定角色", httpMethod = "GET")
    @GetMapping("queryBy/{id}")
    public Employee queryBy(@PathVariable Integer id) {
        return sbiz.queryEmpBy(id);
    }
    @PutMapping("modifyStaff")
    public Map<String,Object> modifyStaff(@RequestBody Employee emp){
        Map<String,Object> message=new HashMap<String,Object>();
        boolean count= sbiz.modifyStaff(emp);
        if (count){
            message.put("code","200");
            message.put("msg","ok");
        }
        return message;
    }
    @ApiOperation(value="模糊查询", notes = "根据当前页数，每页多少行查询出分页数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path", name = "p", value = "当前页数", example = "1", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="path", name = "s", value = "每页多少行", example = "3", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="path", name = "eno", value = "模糊查询的条件", example = "l", required = true, dataType = "String")
    })
    @GetMapping("like/{p}/{s}/{eno}")
    public PageInfo<StaffVo> queryByLike(@PathVariable Integer p, @PathVariable Integer s,@PathVariable String eno) {
        return sbiz.queryLike(p,s,eno);
    }
}
